package cl.zeke.cursos.jsf2spring3jpa2.vista.managedbeans.gestionar_perfiles;

import cl.zeke.cursos.jsf2spring3jpa2.negocio.entities.Perfil;
import cl.zeke.cursos.jsf2spring3jpa2.negocio.services.ComunesService;
import java.io.Serializable;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 *
 * @author eduardo
 */
@Component
@Scope("flow")
public class GestionarPerfilesBean implements Serializable {
    
    private static Logger log = LoggerFactory.getLogger(GestionarPerfilesBean.class);

    @Autowired
    private ComunesService comunesService;
    
    private Perfil perfil;
    private List<Perfil> perfilList;

    public void iniciar() {
        log.debug("inicio GestionarPerfilesBean");
        perfilList = comunesService.traerTodosLosPerfiles();
    }
    
    public String irEditar(Perfil perfil) {
        if(perfil == null) {
            return "crear";
        }
        
        this.perfil = perfil;
        return "editar";
    }

    public Perfil getPerfil() {
        return perfil;
    }

    public void setPerfil(Perfil perfil) {
        this.perfil = perfil;
    }

    public List<Perfil> getPerfilList() {
        return perfilList;
    }
}
